package com.huawei.appmarket.service.distribution.permission;

import android.app.Activity;
import android.content.DialogInterface;
import android.os.Bundle;
import androidx.annotation.Nullable;
import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.appgallery.foundation.ui.framework.activity.BaseActivity;
import com.huawei.appmarket.R;
import com.huawei.appmarket.service.distribution.net.view.DistributionNetActivityProtocol;
import com.huawei.appmarket.service.distribution.net.view.DistributionNetActivityProtocol.Request;
import com.huawei.secure.android.common.intent.SafeIntent;
import java.util.ArrayList;
import java.util.List;
import o.cjk;
import o.cjm;
import o.cjo;
import o.Logger;
import o.doo;
import o.dph;
import o.dpi;
import o.dtt;
import o.dvt;
import o.dxi;
import o.dxq;
import o.CollectCheck;
import o.evd;
import o.evk;
import o.ewa;

public class DistributionPermissionActivity extends BaseActivity<DistributionPermissionActivityProtocol> implements ewa {
    private DistributionPermissionActivityProtocol ॱˊ;

    static {
        dpi.ˎ(DistributionPermissionActivity.class);
    }

    public void onCreate(@Nullable Bundle bundle) {
        requestWindowFeature(1);
        super.onCreate(bundle);
        evd.ˏ(getWindow());
        ArrayList arrayList = new ArrayList();
        Bundle bundleExtra = new SafeIntent(getIntent()).getBundleExtra("distribution_permission_bundle_key");
        if (bundleExtra != null) {
            Object parcelableArrayList = bundleExtra.getParcelableArrayList("permission_info_list_key");
        } else {
            ArrayList arrayList2 = arrayList;
        }
        if (CollectCheck.isEmpty(parcelableArrayList)) {
            Logger.e("DistributionPermissionActivity", "permission info is null!");
            finish();
            return;
        }
        this.ॱˊ = (DistributionPermissionActivityProtocol) ʾ();
        if (this.ॱˊ == null || this.ॱˊ.ॱ() == null) {
            Logger.e("DistributionPermissionActivity", "protocol is null!");
            finish();
            return;
        }
        dtt ˋ = dtt.ˋ(this, parcelableArrayList);
        ˋ.ˋ(this);
        ˋ.ॱ(-1, getString(R.string.wisedist_app_permission_button_content));
        ˋ.ˎ(this);
    }

    public void ˏ(Activity activity, DialogInterface dialogInterface, int i) {
        if (i == -1) {
            Logger.ˎ("DistributionPermissionActivity", "agree the PermissionDialog");
            int ˏ = this.ॱˊ.ॱ().ˏ();
            int ॱ = this.ॱˊ.ॱ().ॱ();
            List ˎ = this.ॱˊ.ॱ().ˎ();
            List ˋ = this.ॱˊ.ॱ().ˋ();
            if (dxi.ॱ(this, ˏ, ॱ)) {
                ˋ(ˎ, ˋ);
            } else if (doo.ˊ(this)) {
                ॱ(ˎ, ˋ);
            } else {
                evk.ॱ(getResources().getString(R.string.no_available_network_prompt_toast), 0).ˋ();
                ᐝ();
            }
            finish();
        } else if (i == -2) {
            Logger.ˎ("DistributionPermissionActivity", "disagree the PermissionDialog");
            ᐝ();
            finish();
        }
    }

    private void ॱ(List<String> list, List<String> list2) {
        SessionDownloadTask ˋ;
        if (!CollectCheck.isEmpty(list)) {
            for (String ˋ2 : list) {
                ˋ = dvt.ˏ().ˋ(ˋ2);
                if (ˋ != null) {
                    ˋ.ˋॱ(8);
                    dvt.ˏ().ˊ(ˋ.ʾ());
                }
            }
        }
        if (!CollectCheck.isEmpty(list2)) {
            for (String ˋ22 : list2) {
                ˋ = dph.ˋ().ॱ(ˋ22);
                if (ˋ != null) {
                    ˋ.ˋॱ(8);
                    dvt.ˏ().ॱ(ˋ, false);
                }
            }
        }
    }

    private void ˋ(List<String> list, List<String> list2) {
        cjo distributionNetActivityProtocol = new DistributionNetActivityProtocol();
        Request request = new Request();
        request.ॱ(list);
        request.ˎ(list2);
        request.ˋ(this.ॱˊ.ॱ().ˊ());
        distributionNetActivityProtocol.ˊ(request);
        cjk.ˎ().ˋ(this, new cjm("distribution.net.activity", distributionNetActivityProtocol));
    }

    public void ˊ(Activity activity, DialogInterface dialogInterface) {
        Logger.ˎ("DistributionPermissionActivity", "cancel the PermissionDialog");
        ᐝ();
        finish();
    }

    private void ᐝ() {
        List<String> ˋ = this.ॱˊ.ॱ().ˋ();
        if (!CollectCheck.isEmpty(ˋ)) {
            for (String ॱ : ˋ) {
                SessionDownloadTask ॱ2 = dph.ˋ().ॱ(ॱ);
                if (ॱ2 != null) {
                    dxq.ˎ(ॱ2, this);
                }
            }
        }
    }

    public void ᐝᐝ() {
    }
}
